package net.ttny.java.web.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Json {

	public static void main(String[] args) {
		//1. List集合转换成json代码
		/*List list = new ArrayList();
		List l1 = new ArrayList();

		list.add( l1 );
		list.add( "second" );

		JSONArray jsonArray2 = JSONArray.fromObject( list );
		System.out.println(jsonArray2);*/

		//2. Map集合转换成json代码
		/*Map map = new HashMap();

		map.put("name", "json");
		map.put("bool", Boolean.TRUE);
		map.put("int", new Integer(1));
		map.put("arr", new String[] { "a", "b" });
		map.put("func", "function(i){ return this.arr[i]; }");

		JSONObject json = JSONObject.fromObject(map);
		JSONArray son = json.getJSONArray("arr");
		System.out.println(son+son.getString(0));
		System.out.println(json);*/

		//3. Bean转换成json代码

		/*JSONObject jsonObject = JSONObject.fromObject(new JsonBean());*/

		//4. 数组转换成json代码

		/*boolean[] boolArray = new boolean[] { true, false, true };
		String[] test = new String[] {"a", "b", "c"};

		JSONArray jsonArray1 = JSONArray.fromObject(test);
		System.out.println(jsonArray1);*/
	}
}
